'''
Created on 15 mai 2009

@author: tmeedendorp
'''
from util.list_util import *
from util.string_util import *
from manager.bean_store      import *

class CountWordsComputor(object):
    def __init__(self):
        self.wordsDictionary = {}
        self.configurationManager = getBean("configurationManager")
        self.name = "Comptage des mots";
        
        
    def processWord(self, word, lineNumber):
        if self.configurationManager.isWordIgnored(word):
            return
        count = self.wordsDictionary.get(word, None)
        if count == None:
            self.wordsDictionary[word] = 1
        else:
            count+=1
            self.wordsDictionary[word] = count
            
    
    def writeHTMLResult(self, file):
        for value in getListFromDictionarySortedByValue(self.wordsDictionary):
            if(value[1] > 2):
                file.write("<div><span>"+value[0]+" : </span><span style=\"color:blue\">"+str(value[1]) +"</span></div>\n")
            